package fisherrors

import (
	"github.com/pkg/errors"
)

type ErrCode int

func (e ErrCode) ToFishError() *FishError {
	return &FishError{
		Err:  errors.New(e.String()),
		Code: int(e),
	}
}

//go:generate stringer -type ErrCode -linecomment
const (
	CodeOk          ErrCode = 0 // success
	CodeTimeout     ErrCode = 1 // 超时
	FishErrorFlag   ErrCode = 2 // ❌❌❌❌❌❌❌❌❌❌❌
	FishNoErrorFlag ErrCode = 3 // ✅✅

	CodeParamError      ErrCode = 300 // 参数错误
	FishCodeParamError2 ErrCode = 301 // 参数错误

	// 1000-2000 数据库错误
	CodeDatabaseIsNotAllowEmpty ErrCode = 1000 // 数据库不允许为空
	CodeDataQueryError          ErrCode = 1001 // 数据查询错误

	// 2000-3000 库存业务错误
	SkuListAndPeriodListNotAllowAllAreEmpty     ErrCode = 2001 // 插入detail的数据，sku列表和period列表不能都为空
	PeriodIdMustExist                           ErrCode = 2002 // period_id必须存在
	PeriodIdMustBeInt                           ErrCode = 2003 // period_id必须是整形
	OperationTypeExist                          ErrCode = 2004 // operation_type必须存在
	OperationTypeMustBeInt                      ErrCode = 2005 // operation_type必须是整数
	OperationTypeMustBeInList                   ErrCode = 2006 // operation_type必须是后台更新的指定类型
	SmallStockMustExist                         ErrCode = 2007 // small_stock必须存在
	SmallStockMustBeGeZero                      ErrCode = 2008 // small_stock必须>=0
	BigStockMustExist                           ErrCode = 2009 // big_stock必须存在
	BigStockMustBeGeZero                        ErrCode = 2010 // bigStock必须>=0
	PeriodSkuIdMustExist                        ErrCode = 2011 // period_sku_id必须存在
	CodeSkuStockNotEnough                       ErrCode = 2012 // 营期库存不足
	CodeSkuStockOverFlow                        ErrCode = 2013 // sku总库存 超限
	CodePeriodStockNotEnough                    ErrCode = 2014 // 营期库存不足
	CodePeriodStockOverFlow                     ErrCode = 2015 // 营期库存超限
	CodeSpecIsRepeat                            ErrCode = 2016 // selectSpecValues is repeat 同一个规格类型选择了多个规格值
	CodeSpecIsNotExist                          ErrCode = 2017 // 规格不存在
	CodeSelectSpecValuesIsInvalid               ErrCode = 2018 // selectSpecValues is invalid 出现了不存在于本营期的规格值
	CodeUpdateStockParamError                   ErrCode = 2019 // updateStockParam param error SmallNumber and BigNumber < 0
	CodeUpdateStockParamOperationTypeIsNotExist ErrCode = 2020
)
